﻿Imports SiNet.Factory

Public Class Main
    Public jConnected As Boolean
    Public inMessage As String
    Public tmpStation As String
    Public tmpArtist As String
    Public tmpTitle As String
    Public captchaCode As String
    Public theCountryURL As String
    Dim doClose As Boolean = False
    Dim title, artist, station, sirenStation As String

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        writeLog(4, "Checking for internet connection...", True)
        If My.Application.SplashScreen.Visible = True Then
            Dim aResult As IAsyncResult = My.Application.SplashScreen.BeginInvoke( _
            New SplashScreen.UpdateStatusLabel(AddressOf SplashScreen.UpdateLabelTextInternetConnection))
        End If
        ''Make this check look for a new version of the station_info.xml document
        ''If it finds the document, there is a good internet connection
        ''if not then there isn't an internet connection
        If Not IsConnectionAvailable() Then
            MessageBox.Show("You must have an active internet connection to use SiNet. " & _
                            "You may have a firewall or proxy that is blocking access. " & _
                            "SiNet will open but will most likely be crippled.", _
                            "- SiNet Error -", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If

        writeLog(4, "Checking for program update...", True)
        If My.Application.SplashScreen.Visible = True Then
            Dim aResult As IAsyncResult = My.Application.SplashScreen.BeginInvoke( _
            New SplashScreen.UpdateStatusLabel(AddressOf SplashScreen.UpdateLabelTextUpdates))
        End If
        If checkForUpdate() = 1 Then
            ToolStripStatusLabelUpdate.Visible = True
        End If

        writeLog(4, "Loading user settings...", False)
        Me.Height = 135
        If My.Application.SplashScreen.Visible = True Then
            Dim aResult As IAsyncResult = My.Application.SplashScreen.BeginInvoke( _
            New SplashScreen.UpdateStatusLabel(AddressOf SplashScreen.UpdateLabelTextUserSettings))
        End If

        ''Sign-in to SiNetSiren, maybe
        If My.Settings.sinetSirenOnConnect Then
            writeLog(4, "Starting SiNet Siren...", False)
            If My.Application.SplashScreen.Visible = True Then
                Dim aResult As IAsyncResult = My.Application.SplashScreen.BeginInvoke( _
                New SplashScreen.UpdateStatusLabel(AddressOf SplashScreen.UpdateLabelTextSinetSiren))
            End If
            If My.Settings.sinetSirenUser.Length > 0 And My.Settings.sinetSirenPass.Length > 0 Then
                Try
                    JabberClient1.User = My.Settings.sinetSirenUser
                    JabberClient1.Password = My.Settings.sinetSirenPass
                    JabberClient1.Connect()
                Catch ex As Exception
                    writeLog(4, "error follows.", True)
                    writeLog(3, ex.Message, True)
                End Try
            Else
                writeLog(4, "error.", True)
            End If
            writeLog(4, "done.", True)
        Else
            writeLog(4, "SiNet Siren was NOT started. Check your settings.", True)
        End If

        ''If the country code isn't set open directly to the settings form
        If My.Settings.sinetCountry.Length = 0 Then
settings:
            If SettingsForm.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
                If MessageBox.Show("You must save your settings to use SiNet", "- SiNet Error -", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Cancel Then
                    Application.Exit()
                Else
                    GoTo settings
                End If
            End If
        End If
        setCountryURL()
        ''If there are no user settings then don't enable the login button
        If Not (My.Settings.sinetUser.Length > 0) Or Not (My.Settings.sinetPass.Length > 0) Then
            LoginToolStripMenuItem.Enabled = False
        End If
        ShowSongArchiveToolStripMenuItem.Enabled = My.Settings.sinetLogSong
        NotifyIconMain.Visible = My.Settings.sinetTaskTrayOn
        ShowInTaskbar = My.Settings.sinetTaskBarOn
        writeLog(5, "done.", True)

    End Sub

    Private Sub ComboStreamBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboStreamBox.KeyDown, ComboStreamBox.KeyUp
        If Not ComboStreamBox.DroppedDown Then
            e.SuppressKeyPress = True
            ComboStreamBox.DroppedDown = True
        End If
    End Sub

    Private Sub ComboStreamBox_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboStreamBox.SelectedValueChanged
        loadStream()
    End Sub

    Private Sub SettingsToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsToolStripMenuItem.Click, SettingsContextMenuItem.Click
        SettingsForm.ShowDialog()
    End Sub

    Private Sub AboutToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click, AboutContextMenuItem.Click
        AboutBox.ShowDialog()
    End Sub

    Private Sub LoginToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginToolStripMenuItem.Click
        Dim proLog As String = Nothing
        setCountryURL()
        ''load login page and login
        writeLog(4, "Loading user log-in form...", True)
        getURL(theCountryURL, "login")
        If CaptchaDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            CaptchaDialog.Dispose()
            If doLogin() <> 1 Then
                ''now if we're logged in, get the streams
                If getURL(theCountryURL, "getstreams") <> 1 Then
                    ''I have streams to show, resize the main window
                    Me.Height = 230
                    ''Now disable the log-in button
                    LoginToolStripMenuItem.Enabled = False
                    LoginToolStripMenuItem.ToolTipText = "Exit SiNet to logout."
                End If
                proLog = "log-in"
            Else
                ToolStripStatusLabel1.Text = "Could not log-in or get streams!"
                writeLog(1, "Could not log-in or get streams!", True)
            End If
        Else
            ToolStripStatusLabel1.Text = "User cancelled captcha dialog."
            proLog = "captcha cancel"
        End If
        writeLog(5, "Completed " & proLog & " process.", True)
    End Sub

    Private Sub axWindowsMediaPlayer1_ScriptCommand(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_ScriptCommandEvent) Handles AxWindowsMediaPlayer1.ScriptCommand
        ''This catches the song info passed in the stream
        On Error Resume Next
        Dim songInfo As Array = Split(e.param.ToString, "|")
        If songInfo.Length > 1 Then
            ''move the last broadcast and compare
            Dim oldTitle As String = title
            Dim oldArtist As String = artist
            Dim newTitle As String = songInfo(1).ToString.Remove(0, 6)
            Dim newArtist As String = songInfo(2).ToString.Remove(0, 7)
            ''if the song has changed, update a few things
            If Not oldTitle = newTitle Then
                title = newTitle
                artist = newArtist
                ''Update main form label
                LabelSongArtist.Text = artist
                LabelSongTitle.Text = title
                ''Update task tray notification
                NotifyIconMain.Text = "SiNet - (" & station & ") " & artist & " - " & title
                ''Write to the app log
                AppLogForm.TextBoxWebInfo.AppendText(Date.Now.ToString & vbNewLine & "ARTIST: " & artist & vbNewLine & "TITLE: " & title & vbNewLine & "-----------" & vbNewLine)
                If My.Settings.sinetNotification > 0 Then
                    NotificationWindowForm.LabelStation.Text = station
                    NotificationWindowForm.LabelArtist.Text = artist
                    NotificationWindowForm.LabelTitle.Text = title
                    NotificationWindowForm.Show()
                End If
                If My.Settings.sinetLogSong Then
                    ''Write the date, station, and song info to csv
                    File.AppendAllText("songinfo.csv", Date.Now.ToString & "," & station & _
                                       "," & artist & "," & title & vbNewLine)
                End If
            End If
        End If
    End Sub

    Private Sub WindowToolStripMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowWindowContextMenuItem.Click
        If Not FormWindowState.Normal Then
            Show()
            WindowState = FormWindowState.Normal
        End If
        Me.BringToFront()
    End Sub

    Private Sub ButtonStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonStop.Click
        stopPlayer()
    End Sub

    Private Sub ButtonMute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMute.Click
        mutePlayer()
    End Sub

    Private Sub LinkLabelSirius_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelSirius.LinkClicked
        If My.Settings.sinetCountry = "us" Then
            System.Diagnostics.Process.Start("http://www.sirius.com")
        ElseIf My.Settings.sinetCountry = "ca" Then
            System.Diagnostics.Process.Start("http://www.siriuscanada.ca")
        End If
    End Sub

    Private Sub Main_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If (FormWindowState.Minimized = WindowState) Then
            If My.Settings.sinetTaskTrayOn And Not My.Settings.sinetTaskBarOn Then
                Me.Hide()
            End If
        End If
    End Sub

    Private Sub ShowBrowserToolStripMenuItem_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowBrowserToolStripMenuItem.Click
        If ShowBrowserToolStripMenuItem.Checked Then
            ''show the browser window
            Browser.Visible = True
        Else
            Browser.Visible = False
        End If
    End Sub

    Private Sub ShowLogToolStripMenuItem_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowLogToolStripMenuItem.Click
        If ShowLogToolStripMenuItem.Checked Then
            ''Show the applog window
            AppLogForm.Visible = True
        Else
            ''Hide the applog window
            AppLogForm.Visible = False
        End If
    End Sub

    Private Sub ShowSongArchiveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowSongArchiveToolStripMenuItem.Click
        SongLog.ShowDialog()
        SongLog.Dispose()
    End Sub

    Private Sub TrackBarVolume_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBarVolume.Scroll
        AxWindowsMediaPlayer1.settings.volume = TrackBarVolume.Value
    End Sub

    Private Sub NotifyIconMain_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIconMain.MouseDoubleClick
        If Not FormWindowState.Normal Then
            Show()
            WindowState = FormWindowState.Normal
        End If
        Me.BringToFront()
    End Sub

    Private Sub ToolStripStatusLabelUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripStatusLabelUpdate.Click
        Process.Start("http://sourceforge.net/projects/sinet")
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitContextMenuItem.Click, ExitToolStripMenuItem.Click
        Dim confirm As DialogResult = MessageBox.Show("Are you sure you want to exit SiNet?", "-SiNet Exit Confirmation -", MessageBoxButtons.YesNo, MessageBoxIcon.Stop)
        If confirm = Windows.Forms.DialogResult.Yes Then
            doClose = True
            Me.Close()
        End If
    End Sub

    Private Sub StationGuideToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StationGuideToolStripMenuItem.Click, StationGuideContextItem.Click
        Guide.Show()
    End Sub

    Private Sub WebsiteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WebsiteToolStripMenuItem.Click
        Process.Start("http://sourceforge.net/projects/sinet")
    End Sub

    Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopControlsContextMenuItem.Click
        stopPlayer()
    End Sub

    Private Sub MuteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MuteControlsContextMenuItem.Click
        mutePlayer()
    End Sub

    Private Sub SongAlertsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SongAlertsToolStripMenuItem.Click
        SongAlerts.ShowDialog()
        SongAlerts.Close()
    End Sub

    Private Sub JabberClient1_OnAuthError(ByVal sender As Object, ByVal rp As System.Xml.XmlElement) Handles JabberClient1.OnAuthError
        jConnected = False
        MessageBox.Show("Could not log-in to your SiNet Siren account." & vbNewLine _
                        & "Check your SiNet Siren username and password and try again.", "- SiNet Siren Authentication Failure -", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Sub

    Private Function JabberClient1_OnInvalidCertificate(ByVal sender As Object, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean Handles JabberClient1.OnInvalidCertificate
        Return True
    End Function

    Private Sub JabberClient1_OnAuthenticate(ByVal sender As Object) Handles JabberClient1.OnAuthenticate
        jConnected = True
        On Error Resume Next
        If Not SettingsForm.TextBoxSirenUser.Text = Nothing And Not SettingsForm.TextBoxSirenPass.Text = Nothing Then
            My.Settings.sinetSirenUser = SettingsForm.TextBoxSirenUser.Text
            My.Settings.sinetSirenPass = SettingsForm.TextBoxSirenPass.Text
        End If
        If Not SongAlerts.IsDisposed Then
            SongAlerts.signOnForms()
            SongAlerts.getSirens()
        End If
    End Sub

    Private Sub JabberClient1_OnMessage(ByVal sender As Object, ByVal msg As jabber.protocol.client.Message) Handles JabberClient1.OnMessage
        Try
            ''Process incoming message
            inMessage = msg.Body
            If msg.Body.StartsWith("AOK:") And msg.From.User.Equals("bigboy") Then
                ''The add command responded with OK
                SongAlerts.getSirens()
            ElseIf msg.Body.StartsWith("GOK:") And msg.From.User.Equals("bigboy") Then
                ''The get command responded with OK and data
                If tmpStation = Nothing Then
                    SongAlerts.TextBoxAddStation.Text = Nothing
                End If
                If tmpArtist = Nothing Then
                    SongAlerts.TextBoxAddArtist.Text = Nothing
                End If
                If tmpTitle = Nothing Then
                    SongAlerts.TextBoxAddTitle.Text = Nothing
                End If
                SongAlerts.sirenGet()
            ElseIf msg.Body.StartsWith("DOK:") And msg.From.User.Equals("bigboy") Then
                ''The delete request was successful
            ElseIf msg.Body.StartsWith("ALERT:") And msg.From.User.Equals("bigboy") Then
                Try
                    Dim alertText As String = Nothing
                    Dim inMessage As String = msg.Body.Remove(0, 6)
                    Dim alertInfo As Array = Split(inMessage, "%%")
                    sirenStation = alertInfo(0)
                    ''Only show the alert if the station is selectable from the combo box
                    If tuneInTokyo(False, False) = 0 Then
                        alertText = "Station: " & alertInfo(0) & vbNewLine & _
                        "Artist: " & alertInfo(1) & vbNewLine & _
                        "Title: " & alertInfo(2)
                        ''Show balloon tip
                        NotifyIconMain.ShowBalloonTip(5000, "- SiNet Siren Alert -", alertText, ToolTipIcon.Info)
                        If Not ToolStripComboBoxRecentSirens.Enabled Then
                            ToolStripComboBoxRecentSirens.Enabled = True
                            RecentSirensComboBoxMenuItem.Enabled = True
                        End If
                        ''Add to recent alerts list(s)
                        If ToolStripComboBoxRecentSirens.Items.Count > 10 Then
                            ''Remove the firt item if there would be more then 10 in the list
                            ToolStripComboBoxRecentSirens.Items.Remove(0)
                            RecentSirensComboBoxMenuItem.Items.Remove(0)
                        End If
                        ToolStripComboBoxRecentSirens.Items.Add(alertInfo(0) & ": " & alertInfo(1) & " - " & alertInfo(2) _
                                                                & " (" & Date.Now.ToShortTimeString & ")")
                        RecentSirensComboBoxMenuItem.Items.Add(alertInfo(0) & ": " & alertInfo(1) & " - " & alertInfo(2) _
                                                                & " (" & Date.Now.ToShortTimeString & ")")
                    End If
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            ElseIf msg.Body.Equals("NOTFOUND") And msg.From.User.Equals("bigboy") Then
                ''My scooter Sasha!
            ElseIf msg.From.User.Equals("bigboy") Then
                MessageBox.Show(inMessage, "- SiNet Admin Alert -", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                ''Do nothing at all
            End If
        Catch ex As Exception
            writeLog(4, ex.Message, True)
        End Try
    End Sub

    Private Sub JabberClient1_OnDisconnect(ByVal sender As Object) Handles JabberClient1.OnDisconnect
        jConnected = False
    End Sub

    Private Sub JabberClient1_OnError(ByVal sender As Object, ByVal ex As System.Exception) Handles JabberClient1.OnError
        jConnected = False
    End Sub

    Private Sub NotifyIconMain_BalloonTipClicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIconMain.BalloonTipClicked
        tuneInTokyo(True, True)
    End Sub

    Private Sub AddArtistSirenMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddArtistSirenMenuItem.Click
        tmpStation = Nothing
        tmpArtist = artist
        tmpTitle = Nothing
        SongAlerts.ShowDialog()
    End Sub

    Private Sub AddTitleOnlySirenMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddTitleOnlySirenMenuItem.Click
        tmpStation = Nothing
        tmpArtist = Nothing
        tmpTitle = title
        SongAlerts.ShowDialog()
    End Sub

    Private Sub AddArtistTitleSirenMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddArtistTitleSirenMenuItem.Click
        tmpStation = Nothing
        tmpArtist = artist
        tmpTitle = title
        SongAlerts.ShowDialog()
    End Sub

    Private Sub AddStationArtistSirenMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddStationArtistSirenMenuItem.Click
        tmpStation = station
        tmpArtist = artist
        tmpTitle = Nothing
        SongAlerts.ShowDialog()
    End Sub

    Private Sub AddStationArtistTitleSirenMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddStationArtistTitleSirenMenuItem.Click
        tmpStation = station
        tmpArtist = artist
        tmpTitle = title
        SongAlerts.ShowDialog()
    End Sub

    Private Sub AddStationTitleSirenMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddStationTitleSirenMenuItem.Click
        tmpStation = station
        tmpArtist = Nothing
        tmpTitle = title
        SongAlerts.ShowDialog()
    End Sub

    Private Sub ToolStripComboBoxRecentSirens_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripComboBoxRecentSirens.SelectedIndexChanged
        Dim selStation As Array = ToolStripComboBoxRecentSirens.SelectedItem.ToString.Split(":")
        sirenStation = selStation(0).ToString.Trim()
        tuneInTokyo(True, True)
        ''keep the other box in sync
        RecentSirensComboBoxMenuItem.SelectedIndex = ToolStripComboBoxRecentSirens.SelectedIndex
    End Sub

    Private Sub RecentSirensComboBoxMenuItem_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RecentSirensComboBoxMenuItem.SelectedIndexChanged
        Dim selStation As Array = RecentSirensComboBoxMenuItem.SelectedItem.ToString.Split(":")
        sirenStation = selStation(0).ToString.Trim()
        tuneInTokyo(True, True)
        ''keep the other box in sync
        ToolStripComboBoxRecentSirens.SelectedIndex = RecentSirensComboBoxMenuItem.SelectedIndex
    End Sub

    Public Sub sendMessage(ByVal user As String, ByVal theMesg As String)
        Try
            Dim msg As New client.Message(JabberClient1.Document)
            msg.To = New jabber.JID(user)
            msg.Body = theMesg
            JabberClient1.Write(msg)
        Catch ex As Exception
            MessageBox.Show("Error sending message: " & ex.Message)
        End Try
    End Sub

    Public Function setCountryURL() As String
        If My.Settings.sinetCountry.Length > 0 Then
            If My.Settings.sinetCountry.EndsWith("us") Then
                theCountryURL = My.Settings.hostUS
                LinkLabelSirius.Text = "http://www.sirius.com"
            ElseIf My.Settings.sinetCountry.EndsWith("ca") Then
                theCountryURL = My.Settings.hostCA
                LinkLabelSirius.Text = "http://www.siriuscanada.ca"
            Else
                LinkLabelSirius.Visible = False
            End If
        End If
        Return ""
    End Function

    Private Function loadStream() As Integer
        Try
            ''Set the station variable
            station = ComboStreamBox.SelectedItem
            ''This yanks off the station number because my station parser only wants the stream name
            ''If you want to see the syntax of expected combo items
            ''check the ChannelParser function in the factory
            If My.Settings.sinetSortByName Then
                If station.Contains("(") Then
                    station = station.Substring(0, (station.IndexOf("(") - 1))
                End If
            Else
                If station.Contains("-") Then
                    station = station.Remove(0, 6)
                End If
            End If
            writeLog(4, "Requesting station: " & station, True)
            ''turn off the label overlay
            LabelComboOverLay.Visible = False
            ''Changes song info display
            LabelSongArtist.Text = "Loading Artist..."
            LabelSongTitle.Text = "Loading Title..."
            ''Update status label
            ToolStripStatusLabel1.Text = "Retrieving stream URL..."
            writeLog(4, "Retrieving stream URL...", True)
            If station.Length > 0 Then
                Dim newStream As String = getLandingPage(theCountryURL, station)
                If newStream.Length > 0 Then
                    If getURL(newStream) <> 0 Then
                        GoTo error105
                    End If
                    If getStreamDetails(theCountryURL, station) <> 0 Then
                        GoTo error105
                    End If
                    ToolStripStatusLabel1.Text = "Ready to play stream " & station & "."
                    writeLog(4, "Ready to play stream " & station & ".", True)
                Else
                    GoTo error105
                End If
            Else
error105:
                ToolStripStatusLabel1.Text = "Error retriving stream for " & station & "."
                writeLog(1, "Error retriving stream for " & station & ".", True)
            End If
        Catch ex As Exception
            writeLog(1, ex.Message, False)
        End Try
    End Function

    Private Function stopPlayer() As Integer
        ''the WMP stop control
        If AxWindowsMediaPlayer1.playState = WMPPlayState.wmppsPlaying Then
            AxWindowsMediaPlayer1.Ctlcontrols.stop()
            ''Main Button
            ButtonStop.Text = "Play"
            ''Context button
            StopControlsContextMenuItem.Text = "Play"
            ''Task tray icon text
            NotifyIconMain.Text = "SiNet"
            ''Main window
            LabelSongArtist.Text = Nothing
            LabelSongTitle.Text = "Playback Stopped."
            artist = Nothing
            title = Nothing
            Return 0
        Else
            ''The streams will expire, so this will just reload the existing combobox selection
            loadStream()
            ''Main Button
            ButtonStop.Text = "Stop"
            ''Context button
            StopControlsContextMenuItem.Text = "Stop"
            LabelSongArtist.Text = "Loading Artist..."
            LabelSongTitle.Text = "Loading Track..."
            Return 0
        End If
        Return 1
    End Function

    Private Function mutePlayer() As Integer
        ''the WMP mute control
        If AxWindowsMediaPlayer1.settings.mute Then
            AxWindowsMediaPlayer1.settings.mute = False
            ''Main button
            ButtonMute.Text = "Mute"
            ''Context control
            MuteControlsContextMenuItem.Text = "Mute"
            Return 0
        Else
            AxWindowsMediaPlayer1.settings.mute = True
            ''Main button
            ButtonMute.Text = "Unmute"
            ''Context control
            MuteControlsContextMenuItem.Text = "Unmute"
            Return 0
        End If
        Return 1
    End Function

    Private Function tuneInTokyo(ByVal prompt As Boolean, ByVal tune As Boolean) As Integer
        Dim x As Integer
        Dim theStationIndex As Integer = Nothing
        If ComboStreamBox.Items.Count > 1 Then
            For Each textItem In ComboStreamBox.Items
                If textItem.ToString.ToLower.Contains(sirenStation.ToLower) Then
                    theStationIndex = x
                End If
                x += 1
            Next
            ''Check if we found a legit station
            If theStationIndex = Nothing Then
                ''Nothing was found
                If prompt Then
                    MessageBox.Show("Sorry, I couldn't find " & sirenStation & " in the stream selection box. " & x, "- SiNet Info -", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
                ''Exit with error
                Return 1
            Else
                ''We found a station so let's make sure we're not already listening
                If theStationIndex = ComboStreamBox.SelectedIndex Then
                    ''Exit with mixed results
                    Return 2
                End If
            End If
            ''Now we're working with a station Index
            ''See if we asked to tune the station
            If tune And Not theStationIndex = Nothing Then
                ComboStreamBox.SelectedIndex = theStationIndex
            End If
            Return 0
        ElseIf prompt Then
            MessageBox.Show("You must log-in before you can listen to " & sirenStation & ".", "- SiNet Info -", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        Return 2
    End Function

    Private Sub UpdateCheckTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateCheckTimer.Tick
        If checkForUpdate() = 1 Then
            ToolStripStatusLabelUpdate.Visible = True
        End If
    End Sub

End Class